﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtletIS.Shared.Helpers
{
    public static class TimeSpanHelper
    {
        
        /// <summary>
        ///  Konvertuje stringový čas v stotinách na TimeSpan.
        /// </summary>
        public static TimeSpan FromDbResultString(string strTime)
        {
            int hours, minutes, seconds, hundreds;
            strTime = strTime.PadLeft(8, '0');

            hours = Convert.ToInt32(strTime.Substring(0, 2));
            minutes = Convert.ToInt32(strTime.Substring(2, 2));
            seconds = Convert.ToInt32(strTime.Substring(4, 2));
            hundreds = Convert.ToInt32(strTime.Substring(6, 2));

            return new TimeSpan(0, hours, minutes, seconds, hundreds * 10);
        }

        /// <summary>
        ///  Konvertuje TimeSpan na stringový čas v stotinách.
        /// </summary>
        public static string ToDbResultString(TimeSpan ts)
        {
            return string.Format("{0}{1:00}{2:00}{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10);
        }

    }
}
